package com.jd.bluej.dubboj.filter;

import java.io.IOException;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;

public class RestContainerResponseFilter implements ContainerResponseFilter {

	public void filter(ContainerRequestContext containerRequestContext,
			ContainerResponseContext containerResponseContext)
			throws IOException {
		System.out.println("--------------RestContainerResponseFilter------------------------------");

		//跨越请求转换为options请求需要设值头部信息
		if (containerRequestContext.getMethod().equals("OPTIONS")) {
			containerResponseContext.getHeaders().add(
					"Access-Control-Allow-Origin", "*");
			containerResponseContext
					.getHeaders()
					.add("Access-Control-Allow-Headers",
							"Content-Type,x-requested-with,Authorization,Access-Control-Allow-Origin");
			containerResponseContext.getHeaders().add(
					"Access-Control-Allow-Methods", "POST, GET, OPTIONS");
			containerResponseContext.getHeaders().add("Access-Control-Max-Age",
					"360");
		}
	}
	

}
